<?php
$authenticationService = new AuthenticationService();
switch ($action) {
	case "edit":

		if(isset($_POST['btn_submit']))
		{
			$glb["websiteURL"] = $_POST['websiteURL'];
			$glb["settingDir"] = $_POST['settingDir'];
			$glb["layoutDir"] = $_POST['layoutDir'];
			$glb["controllerDir"] = $_POST['controllerDir'];
			$glb["contactEmail"] = $_POST['contactEmail'];

			// write configuration back
			// read configuration data and get reference to root
			$c0 = new Config();
			$root0 =& $c0->parseConfig($glb, "PHPArray");
				
			$options0 = array('name' => 'glb');
			// write configuration to file as PHP array
			$c0->writeConfig(dirname(__FILE__).DIRECTORY_SEPARATOR."../../_config/setting/global.setting.php", "PHPArray", $options0);
				
				
			$configPage['limit'] = $_POST['limit'];
			$configPage["tag"]["curPage"] = $_POST['curPage'];
			$configPage["tag"]["firstLastPage"] = $_POST['firstLastPage'];
			$configPage["tag"]["pageNum"] = $_POST['pageNum'];

			// write configuration back
			// read configuration data and get reference to root
			$c = new Config();
			$root =& $c->parseConfig($configPage, "PHPArray");
			$options = array('name' => 'configPage');
			// write configuration to file as PHP array
			$c->writeConfig(dirname(__FILE__).DIRECTORY_SEPARATOR."../../_config/setting/PageConfig.php", "PHPArray", $options);
				
			$c1 = new Config();
			$root1 =& $c1->parseConfig(dirname(__FILE__).DIRECTORY_SEPARATOR.'../../_config/setting/setting.ini', 'inifile');
			$settingsSection =& $root1->getItem("section", "BArt-system");
			$host =& $settingsSection->getItem("directive", "BArt_system_MYSQL_HOST");
			$dbName =& $settingsSection->getItem("directive", "BArt_system_MYSQL_NAME");
			$user =& $settingsSection->getItem("directive", "BArt_system_MYSQL_USER");
			$pass =& $settingsSection->getItem("directive", "BArt_system_MYSQL_PASS");
			 
			$host->setContent(Tool::encode($_POST['host'], "sTunnInVietnAm@2012#"));
			$dbName->setContent(Tool::encode($_POST['dbName'], "sTunnInVietnAm@2012#"));
			$user->setContent(Tool::encode($_POST['user'], "sTunnInVietnAm@2012#"));
			$pass->setContent(Tool::encode($_POST['pass'], "sTunnInVietnAm@2012#"));
			 
			$c1->writeConfig();
			//--------------------------------------------------------------------------------------------------------------
			$smtp["host"] = Tool::encode($_POST['hostEmail'], "sTunnInVietnAm@2012#");
			$smtp["port"] = Tool::encode($_POST['port'], "sTunnInVietnAm@2012#");
			$smtp["user"] = Tool::encode($_POST['userHost'], "sTunnInVietnAm@2012#");
			$smtp["pass"] = Tool::encode($_POST['passHost'], "sTunnInVietnAm@2012#");

			// write configuration back
			// read configuration data and get reference to root
			$c2 = new Config();
			$root2 =& $c2->parseConfig($smtp, "PHPArray");
				
			$options2 = array('name' => 'smtp');
			// write configuration to file as PHP array
			$c2->writeConfig(dirname(__FILE__).DIRECTORY_SEPARATOR."../../_config/setting/SMTPConfig.php", "PHPArray", $options2);
			
			// order number
			$num['orderNumber'] = $_POST['orderNumber'];
			$num['invoiceNumber'] = $_POST['invoiceNumber'];
			// write configuration back
			// read configuration data and get reference to root
			$c3 = new Config();
			$root =& $c3->parseConfig($num, "PHPArray");
			$options3 = array('name' => 'num');
			// write configuration to file as PHP array
			$c3->writeConfig(dirname(__FILE__).DIRECTORY_SEPARATOR."../../_config/setting/orderNumber.php", "PHPArray", $options3);
			
			
			// print message
			header("Location:index.php?func=web&opt=config");
		}
		break;
			
	default:
		echo "khong co tinh nang nay";
		break;
}
?>